#!/usr/bin/python3

import sys

# read M row & col
mr = int(sys.argv[1])
mc = int(sys.argv[2])

# read N row & col
nr = int(sys.argv[3])
nc = int(sys.argv[4])

# read X row & col
xr = int(sys.argv[5])
xc = int(sys.argv[6])

#mr = 2
#mc = 3

# read N row & col
#nr = 3
#nc = 2

# read X row & col
#xr = 2
#xc = 2

# validate input parameters
assert mc == nr, "M col not equal to N row"
assert mr == xr, "M row not equal to X row"
assert nc == xc, "N col not equal to X col"

# assuming #1 is matrix M, #2 is matrix N, #3 is matrix X
for line in sys.stdin:
    nums = list(map(int, line.split(",")))
    matrix = nums[0] # matrix number
    r = nums[1] # row number
    row = nums[2:] # row value
    # if M
    if matrix == 1: 
        if r<mr and len(row) == mc: 
            for c in range(mc):
                for k in range(nc):
                    # key is row,col
                    # value is location,value
                    print("{0},{1}\t{2},{3}".format(r, k, c, row[c]))

    # if N
    elif matrix == 2:
        if r<nr and len(row) == nc: 
            for c in range(nc):
                for k in range(mr):
                    print("{0},{1}\t{2},{3}".format(k, c, r, row[c]))

    # if X
    elif matrix == 3:
        if r<xr and len(row) == xc: 
            for c in range(xc):
                # location is -1 to mark the value is from X
                print("{0},{1}\t{2},{3}".format(r, c, -1, row[c]))
